/*
 * Copyright 2009-2015 by WWW.KNET.CN  All rights reserved.
 */
package cn.knet.sp.ncrm.modules.sys.assembly;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import cn.knet.sp.ncrm.common.persistence.AjaxMessage;
import cn.knet.sp.ncrm.common.utils.DateUtils;
import cn.knet.sp.ncrm.common.web.BaseController;
import cn.knet.sp.ncrm.modules.sys.utils.CustomerUtils;
import cn.knet.sp.ncrm.modules.sys.utils.ProductUtils;
import cn.knet.sp.ncrm.modules.sys.utils.RegionUtils;

/**
 * 区域Controller
 * @author ThinkGem
 * @version 2013-5-15
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/assembly")
public class AssemblyController extends BaseController {

	@RequestMapping(value = {"list", ""})
	public String list(Model model) {
		return "modules/sys/assembly/index";
	}

	@RequestMapping(value = "testProductType")
	@ResponseBody
	public Object testPT(String name) {
		AjaxMessage result = AjaxMessage.success();
		try {
			String value = ProductUtils.get(name);
			result.setMessage(value);
		} catch (Exception e) {
			result.makeError("查询失败!系统发生异常");
		}
		return result;
	}

	@RequestMapping(value = "testCustomerFeatureName")
	@ResponseBody
	public Object testCF(String name) {
		AjaxMessage result = AjaxMessage.success();
		try {
			String value = CustomerUtils.getFeatureId(name);
			result.setMessage(value);
		} catch (Exception e) {
			e.printStackTrace();
			result.makeError("查询失败!系统发生异常");
		}
		return result;
	}

	@RequestMapping(value = "testCustomerType")
	@ResponseBody
	public Object testCT(String name) {
		AjaxMessage result = AjaxMessage.success();
		try {
			String value = CustomerUtils.getTypeId(name);
			result.setMessage(value);
		} catch (Exception e) {
			e.printStackTrace();
			result.makeError("查询失败!系统发生异常");
		}
		return result;
	}

	@RequestMapping(value = "testRegion")
	@ResponseBody
	public Object testRegion(String name) {
		AjaxMessage result = AjaxMessage.success();
		try {
			String value = RegionUtils.getRegionId(name);
			result.setMessage(value);
		} catch (Exception e) {
			e.printStackTrace();
			result.makeError("查询失败!系统发生异常");
		}
		return result;
	}

	@RequestMapping(value = "createSession")
	@ResponseBody
	public Object createSession(HttpServletRequest request) {
		AjaxMessage result = AjaxMessage.success();
		try {
			request.getSession().setAttribute("test_time_out","OBJ");
		} catch (Exception e) {
			e.printStackTrace();
			result.makeError("查询失败!系统发生异常");
		}
		return result;
	}

	@RequestMapping(value = "testSession")
	@ResponseBody
	public Object testSession(HttpServletRequest request) {
		AjaxMessage result = AjaxMessage.success();
		try {
			result.put("result",request.getSession().getAttribute("test_time_out")+DateUtils.getTime());
		} catch (Exception e) {
			e.printStackTrace();
			result.makeError("查询失败!系统发生异常");
		}
		return result;
	}
}
